﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SoftwareLogistics.SharepointClient
{
    public partial class FieldControl : UserControl
    {
        public FieldControl()
        {
            InitializeComponent();
        }

        public SPField Field
        {
            get{return (SPField)GetValue(FieldProperty);}
            set{SetValue(FieldProperty, value);}
        }

        public static readonly DependencyProperty FieldProperty = DependencyProperty.Register("Field", typeof(SPField), typeof(FieldControl), new PropertyMetadata(null, OnFieldChanged));

        private static void OnFieldChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
        {
            var control = d as FieldControl;
            control.Field = args.NewValue as SPField;
            if (control.Field.FieldType == FieldTypes.Attachments || control.Field.FieldType == FieldTypes.ContentTypeId || control.Field.Name == "ContentType")
                control.Visibility = Visibility.Collapsed;
            else
            {
                control.Label.Text = control.Field.DisplayName;
                control.EditField.Field = control.Field;
            }
        }
    }
}
